home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / scanf.man < prev    next >
Encoding:
Text File  |  1989-01-21  |  7.5 KB  |  267 lines

  1.  
  2.  
  3.  
  4. SCANF                 C Library Procedures                  SCANF
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      scanf, fscanf, sscanf, vfscanf - formatted input conversion
  10.  
  11. SSYYNNOOPPSSIISS
  12.      ##iinncclluuddee <<ssttddiioo..hh>>
  13.  
  14.      ssccaannff((ffoorrmmaatt [ , pointer ] . . .  ))
  15.      cchhaarr **ffoorrmmaatt;;
  16.  
  17.      ffssccaannff((ssttrreeaamm,, ffoorrmmaatt [ , pointer ] . . .  ))
  18.      FFIILLEE **ssttrreeaamm;;
  19.      cchhaarr **ffoorrmmaatt;;
  20.  
  21.      ssssccaannff((ss,, ffoorrmmaatt [ , pointer ] . . .  ))
  22.      cchhaarr **ss,, **ffoorrmmaatt;;
  23.  
  24.      ##iinncclluuddee <<vvaarraarrggss..hh>>
  25.  
  26.      vvffssccaannff((ssttrreeaamm,, ffoorrmmaatt,, aarrggss))
  27.      FFIILLEE **ssttrreeaamm;;
  28.      cchhaarr **ffoorrmmaatt;;
  29.      vvaa__lliisstt aarrggss;;
  30.  
  31. DDEESSCCRRIIPPTTIIOONN
  32.      _S_c_a_n_f reads from the standard input stream ssttddiinn.  _F_s_c_a_n_f
  33.      reads from the named input _s_t_r_e_a_m.  _S_s_c_a_n_f reads from the
  34.      character string _s.  _V_f_s_c_a_n_f provides an alternate form of
  35.      _f_s_c_a_n_f in which the arguments have already been captured
  36.      using the variable-length argument facilities provided by
  37.      _v_a_r_a_r_g_s(_3).  Each function reads characters, interprets them
  38.      according to a format, and stores the results in its argu-
  39.      ments.  Each expects as arguments a control string _f_o_r_m_a_t,
  40.      described below, and a set of _p_o_i_n_t_e_r arguments indicating
  41.      where the converted input should be stored.
  42.  
  43.      The control string usually contains conversion specifica-
  44.      tions, which are used to direct interpretation of input
  45.      sequences.  The control string may contain:
  46.  
  47.      1.  Blanks, tabs or newlines, which match optional white
  48.          space in the input.
  49.  
  50.      2.  An ordinary character (not %) which must match the next
  51.          character of the input stream.
  52.  
  53.      3.  Conversion specifications, consisting of the character
  54.          %%, an optional assignment suppressing character **, an
  55.          optional numerical maximum field width, and a conversion
  56.          character.
  57.  
  58.      A conversion specification directs the conversion of the
  59.      next input field; the result is placed in the variable
  60.  
  61.  
  62.  
  63. Sprite v1.0               May 15, 1985                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SCANF                 C Library Procedures                  SCANF
  71.  
  72.  
  73.  
  74.      pointed to by the corresponding argument, unless assignment
  75.      suppression was indicated by **.  An input field is defined
  76.      as a string of non-space characters; it extends to the next
  77.      inappropriate character or until the field width, if speci-
  78.      fied, is exhausted.
  79.  
  80.      The conversion character indicates the interpretation of the
  81.      input field; the corresponding pointer argument must usually
  82.      be of a restricted type.  The following conversion charac-
  83.      ters are legal:
  84.  
  85.      %%   a single `%' is expected in the input at this point; no
  86.          assignment is done.
  87.  
  88.      dd   a decimal integer is expected; the corresponding argu-
  89.          ment should be an integer pointer.
  90.  
  91.      oo   an octal integer is expected; the corresponding argument
  92.          should be a integer pointer.
  93.  
  94.      xx   a hexadecimal integer is expected; the corresponding
  95.          argument should be an integer pointer.
  96.  
  97.      ss   a character string is expected; the corresponding argu-
  98.          ment should be a character pointer pointing to an array
  99.          of characters large enough to accept the string and a
  100.          terminating `\0', which will be added.  The input field
  101.          is terminated by a space character or a newline.
  102.  
  103.      cc   a character is expected; the corresponding argument
  104.          should be a character pointer.  The normal skip over
  105.          space characters is suppressed in this case; to read the
  106.          next non-space character, try `%1s'.  If a field width
  107.          is given, the corresponding argument should refer to a
  108.          character array, and the indicated number of characters
  109.          is read.
  110.  
  111.      ee
  112.      ff
  113.          a floating point number is expected; the next field is
  114.          converted accordingly and stored through the correspond-
  115.          ing argument, which should be a pointer to a _f_l_o_a_t.  The
  116.          input format for floating point numbers is an optionally
  117.          signed string of digits possibly containing a decimal
  118.          point, followed by an optional exponent field consisting
  119.          of an E or e followed by an optionally signed integer.
  120.  
  121.      [[   indicates a string not to be delimited by space charac-
  122.          ters.  The left bracket is followed by a set of charac-
  123.          ters and a right bracket; the characters between the
  124.          brackets define a set of characters making up the
  125.          string.  If the first character is not circumflex (^),
  126.          the input field is all characters until the first char-
  127.          acter not in the set between the brackets; if the first
  128.  
  129.  
  130.  
  131. Sprite v1.0               May 15, 1985                          2
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. SCANF                 C Library Procedures                  SCANF
  139.  
  140.  
  141.  
  142.          character after the left bracket is ^, the input field
  143.          is all characters until the first character which is in
  144.          the remaining set of characters between the brackets.
  145.          The corresponding argument must point to a character
  146.          array.
  147.  
  148.      The conversion characters dd, oo and xx may be capitalized or
  149.      preceded by ll to indicate that a pointer to lloonngg rather than
  150.      to iinntt is in the argument list.  Similarly, the conversion
  151.      characters ee or ff may be capitalized or preceded by ll to
  152.      indicate a pointer to ddoouubbllee rather than to ffllooaatt.  The
  153.      conversion characters dd, oo and xx may be preceded by hh to
  154.      indicate a pointer to sshhoorrtt rather than to iinntt.
  155.  
  156.      The _s_c_a_n_f functions return the number of successfully
  157.      matched and assigned input items.  This can be used to
  158.      decide how many input items were found.  The constant EEOOFF is
  159.      returned upon end of input; note that this is different from
  160.      0, which means that no conversion was done; if conversion
  161.      was intended, it was frustrated by an inappropriate charac-
  162.      ter in the input.
  163.  
  164.      For example, the call
  165.  
  166.                int i; float x; char name[50];
  167.                scanf("%d%f%s", &i, &x, name);
  168.  
  169.      with the input line
  170.  
  171.           25   54.32E-1  thompson
  172.  
  173.      will assign to _i the value 25, _x the value 5.432, and _n_a_m_e
  174.      will contain `_t_h_o_m_p_s_o_n_\_0'.  Or,
  175.  
  176.           int i; float x; char name[50];
  177.           scanf("%2d%f%*d%[1234567890]", &i, &x, name);
  178.  
  179.      with input
  180.  
  181.           56789 0123 56a72
  182.  
  183.      will assign 56 to _i, 789.0 to _x, skip `0123', and place the
  184.      string `56\0' in _n_a_m_e.  The next call to _g_e_t_c_h_a_r will return
  185.      `a'.
  186.  
  187. SSEEEE AALLSSOO
  188.      atof(3), getc(3S), printf(3S)
  189.  
  190. DDIIAAGGNNOOSSTTIICCSS
  191.      The _s_c_a_n_f functions return EEOOFF on end of input, and a short
  192.      count for missing or illegal data items.
  193.  
  194.  
  195.  
  196.  
  197. Sprite v1.0               May 15, 1985                          3
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. SCANF                 C Library Procedures                  SCANF
  205.  
  206.  
  207.  
  208. BBUUGGSS
  209.      The success of literal matches and suppressed assignments is
  210.      not directly determinable.
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. Sprite v1.0               May 15, 1985                          4
  264.  
  265.  
  266.  
  267.